{template 'common/header'}
<script>
    $(function(){
        $(".del").on('click',function(){
            var id = $(this).attr('pay_id');
            if(confirm("是否确定删除该记录？")) {
                if (id > 0) {
                    var url = "{php echo $this->createWebUrl('pay',array('op' => 'del'))}";
                    $.ajax({
                        type: 'post',
                        url: url,
                        data: {'id': id},
                        success: function (data) {
                            if (data == 111) {
                                location.reload();
                            } else {
                                alert(data);
                            }
                        }
                    });
                }
            }
        });
        $(".add").click(function(){
            var day = $("#day").val();
            var type_id = $("#type_id").val();
            var se_man = $("#se_man").val();
            var price = $("#price").val();
            var remark = $("#remark").val();
            var content = $("#content").val();
            if(day != '' && type_id > 0 && se_man != '' && price > 0){
                var url = "{php echo $this->createWebUrl('pay',array('op' => 'add'))}";
                $.ajax({
                    type : 'post',
                    url : url,
                    data : {'day' : day, 'type_id' : type_id, 'se_man' : se_man, 'price' : price, 'remark' : remark, 'content' : content},
                    success : function(data){
                        if(data == 111){
                            location.reload();
                        }else{
                            alert(data);
                        }
                    }
                });
            }else{
                alert("请输入相关的内容");
            }

        });
        $(".find").click(function(){
            var start_day = $("#start_day").val();
            var end_day = $("#end_day").val();
            var type_id = $("#type_id").val();
            var se_man = $("#se_man").val();
            var price = $("#price").val();
            var remark = $("#remark").val();
            var content = $("#content").val();
            location.href="{php echo $this->createWebUrl('pay')}&start_day="+start_day+"&type_id="+type_id+"&se_man="+se_man+"&price="+price+"&remark="+remark+"&content="+content+"&end_day="+end_day;
        });
        $(".export-data").click(function(){
            var start_day = $("#start_day").val();
            var end_day = $("#end_day").val();
            var type_id = $("#type_id").val();
            var se_man = $("#se_man").val();
            var price = $("#price").val();
            var remark = $("#remark").val();
            var content = $("#content").val();
            location.href="{php echo $this->createWebUrl('pay',array('op' => 'export'))}&start_day="+start_day+"&end_day="+end_day+"&type_id="+type_id+"&se_man="+se_man+"&price="+price+"&remark="+remark+"&content="+content;
        });
        $(".se-man").change(function(){
            var name = $(this).val();
            $("#se_man").val(name);
        });
    });

</script>
<ul class="nav nav-tabs">
    <li class="active" ><a href="{php echo $this->createWebUrl('pay', array('op'=>'index'))}">支出记录</a></li>
    <li  ><a href="{php echo $this->createWebUrl('pay', array('op'=>'to_add'))}">新增记录</a></li>
    <li  ><a href="{php echo $this->createWebUrl('pay', array('op'=>'type'))}">财务类型</a></li>
</ul>
<div class="main">
    <div class="row" >
        <div class="col-xs-3">支出时间(开始)</div>
        <div class="col-xs-3">支出时间(结束)</div>
        <div class="col-xs-3">支出类型</div>
        <div class="col-xs-3">支出金额</div>
        <div class="col-xs-3">
            <input type="date" class="form-control" {if $day} value="{$start_day}"{/if} id="start_day" />
        </div>
        <div class="col-xs-3">
            <input type="date" class="form-control" {if $day} value="{$end_day}"{/if} id="end_day" />
        </div>
        <div class="col-xs-3">
            <select class="form-control" id="type_id">
                <option value="0">请选择支出类型</option>
                {loop $types $type}
                <option value="{$type['id']}" {if $type_id == $type['id']} selected="selected"{/if}>{$type['name']}</option>
                {/loop}
            </select>
        </div>
        <div class="col-xs-3">
            <input type="text" class="form-control" placeholder="请输入金额" id="price" value="{$price}" />
        </div>
    </div>
    <br />
    <div class="row">
        <div class="col-xs-3">
            <input type="text" class="form-control" placeholder="结算人" id="se_man" value="{$se_man}" />
        </div>
        <div class="col-xs-3">
            <select class="form-control se-man">
                <option value="">历史结算人</option>
                {loop $se_mans $se_man}
                <option value="{$se_man['name']}">{$se_man['name']}</option>
                {/loop}
            </select>
        </div>

        <div class="col-xs-3">
            <input type="text" class="form-control" placeholder="请输入支出明细" id="remark" value="{$remark}" />
        </div>
        <div class="col-xs-3">
            <input type="text" class="form-control" placeholder="备注" id="content" value="{$content}" />
        </div>

    </div>
    <br />
    <div class="row">
        <div class="col-xs-3">
            <button class="btn btn-default find">搜索</button>
            <button class="btn btn-default export-data">导出</button>
        </div>
    </div>
    <br />
    <div>
        <table class="table">
            <tr>
                <th>支出日期</th>
                <th>支出人</th>
                <th>支出类型</th>
                <th>支出明细</th>
                <th>支出费用</th>
                <th>备注</th>
                <th>删除</th>
            </tr>
            {loop $list $l}
            <tr>
                <td>{$l['day']}</td>
                <td>{$l['se_man']}</td>
                <td>{$l['type']}</td>
                <td>{$l['remark']}</td>
                <td>{$l['price']}</td>
                <td>{$l['content']}</td>
                <td>
                    <button class="btn btn-danger del" pay_id="{$l['id']}">删除</button>
                </td>
            </tr>
            {/loop}
        </table>
        <div>
            {$pager}
        </div>
    </div>
</div>



{template 'common/footer'}